package com.pesking.core.sqlparser.processor;

import java.util.Arrays;
import java.util.List;

import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;
import com.pesking.core.util.LogUtils;
import com.pesking.core.util.StringUtils;
import com.pesking.unified.system.SystemManage;

/**
 * 系统ID赋值
 * @author cypei
 * @since 2020-12-27
 */
public class SystemIdSqlParameterHandler extends SqlParameterProcessor{

	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"SYSTEM_ID"});
	}

	@Override
	public void handle(StringBuilder sbSQL, Parameter parameter, List<SqlParameter> processors,SqlParameter sqlParameter) {
		String name = sqlParameter.getName();
		String value = null;
		if (!StringUtils.isBlank(name)) {
			value = parameter.getParameter(name);
			LogUtils.debug("根据参数[" + name + "]取得值[" + value + "].");
		}
		if (StringUtils.isBlank(value)) {
			value = SystemManage.getCurrentSystemId();
		}
		sbSQL.append("'").append(value).append("'");
	}
	 
}
